'''
Created on 31/07/2011

@author: Digao
'''
def toInt(arg):
    return int(arg)

def toStr(a,b):
    return str(a)+' '+str(b)

input = open('input.in')
CASES = int(input.readline())
for case in range(1,CASES+1):
    N = int(input.readline().strip())
    wires =[]
    for i in range(N):
        t = tuple(map(toInt,input.readline().split()))
        wires.append(t)
    wires.sort()
    lastB = 0
    count=0
    for i in range(N-1):
        w=wires[i]
        if w[0]<w[1]:
            for j in range(i+1,N):
                ww = wires[j]
                if ww[1]<w[1]:
                    count+=1
    
    print 'Case #%d: %s'%(case,count)
    


